package com.example.baiguangsystem.mapper;

import com.example.baiguangsystem.entity.Section;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 章节表的mapper类
 *
 * @Author: 27641
 * @ProjectName: BaiGuangSystem
 * @Date: 2022/02/05/22:21
 * @noinspection SpellCheckingInspection
 */
@Mapper
public interface SectionMapper {

    /**
     * 根据书本Id查找其所有章节表的信息
     *
     * @param bookId 需要查找的书本Id
     * @return 查找结果
     */
    @Select("select * from section where section_book_id = #{bookId}")
    public List<Section> findSectionByBookId(@Param("bookId") Integer bookId);

    /**
     * 根据书本Id新增章节
     *
     * @param bookId  新增章节所属的书本Id
     * @param section 新增章节
     */
    @Insert("insert into section(section_book_id,section_name,section_path) value(#{bookId}," +
            "#{section.sectionName},#{section.sectionPath})")
    @Options(useGeneratedKeys = true, keyProperty = "section.sectionId", keyColumn = "section_id")
    public void newAddSectionByBookId(@Param("section") Section section, @Param("bookId") Integer bookId);

    /**
     * 根据章节Id删除章节
     *
     * @param sectionId 需要删除的章节Id
     */
    @Delete("delete from section where section_id=#{sectionId}")
    public void deleteSectionByBookId(@Param("sectionId") Integer sectionId);

    /**
     * 根据章节Id查找章节信息
     *
     * @param sectionId 需要查找的章节Id
     * @return 查找结果
     */
    @Select("select * from section where section_id =#{sectionId}")
    public Section findSectionMessagesBySectionId(@Param("sectionId") Integer sectionId);
}
